/**
 * JAVACC DEMO 1.0
 */
package com.apache.passport.service.plugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.passport.entity.BlackRoster;

/**
 * description:  判断黑名单中是否已经存在当前要存储的IP
 *
 * @author Hou Dayu 创建时间：2016-12-24
 */
public class ContainsIpPlugin implements PluginConnector {

    protected IDao blackRosterDao;

    public void setUctUserDao(IDao blackRosterDao) {
        this.blackRosterDao = blackRosterDao;
    }

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     *
     * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)
     */
    @Override
    public Object execute(ParamsVo arg0) throws Exception {
        BlackRoster blackRoster = (BlackRoster) getInfoByIp(arg0);
        if (!Validator.isEmpty(blackRoster)) {
            return true;
        }
        return false;
    }

    public Object getInfoByIp(ParamsVo<BlackRoster> vo) {
        String brIpaddress = (String) vo.getParams("brIpaddress");
        if (Validator.isNull(brIpaddress)) {
            return null;
        }
        String sql = blackRosterDao.getSql(3);
        MethodParam param = new MethodParam("ByIp", "", sql,
                "com.apache.passport.entity.BlackRoster");
        param.setParams("brIpaddress", brIpaddress);
        return blackRosterDao.selectSingle(param);
    }
}
